<?php
namespace app\manage\controller;

class SystemMenuNew extends Base
{
    public function index(){
        if(request()->isAjax()){
            $page = input('page');
            $limit = input('limit');
            $id = input('id');
            $title = input('title');

            $where = [];
            !empty($id) && $where['id'] = $id;
            !empty($title) && $where['title'] = $title;

            if( ! $count=model('SystemMenuNew')->where($where)->count() ){
                $this->layTable();
            }

            $data = model('SystemMenuNew')
                ->where($where)
                ->limit(($page-1)*$limit, $limit)
                ->order('id desc')
                ->select();

            foreach($data as $k=>&$v){
                $v['icon'] = str_replace('&', '', $v['icon']);
            }

            $this->layTable(0, '', $data, $count);
        }else{
            return view();
        }
    }

    public function edit(){
        if( request()->isAjax() ){
            $data = input();
            if(!empty($data['icon'])) $data['icon'] = '&'.$data['icon'];
            $editRs = model('SystemMenuNew')->isUpdate(true)->save( $data );
            $editRs!==false ? $this->layJson(0, '编辑成功') : $this->layJson(1, model('SystemMenuNew')->getError());
        }else{
            return view();
        }
    }
}